package wsi.gui.detector;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;

import org.rygh.gui.swing.component.STextArea;
import org.rygh.gui.swing.field.SIntegerField;
import org.rygh.gui.swing.field.SStringField;
import org.rygh.gui.swing.view.AbstractSView;
import org.rygh.gui.swing.view.SGridView;
import org.rygh.gui.swing.view.SSimpleGridView;
import org.rygh.gui.swing.view.one.SOneTableView;

import wsi.script.AppConfig;

@SuppressWarnings("serial")
public class DetectorView extends SOneTableView {

	private final SStringField functionField = new SStringField("Function");
	private final STextArea queryArea = new STextArea();
	private final SIntegerField limitField = new SIntegerField("Limit",
			KeyEvent.VK_L);

	public DetectorView() {

		layoutComponents();
	}

	public SStringField getFunctionField() {
		return functionField;
	}

	public SIntegerField getLimitField() {
		return limitField;
	}

	public STextArea getQueryArea() {
		return queryArea;
	}

	private void layoutComponents() {
		AbstractSView child;
		GridBagConstraints c;

		SGridView rightView = new SGridView();

		functionField.setColumns(12);
		functionField.setEditable(false);
		child = functionField.getView();

		c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.anchor = GridBagConstraints.LINE_END;
		rightView.add(child, c);

		limitField.setColumns(12);
		limitField.setEditable(true);
		limitField.setValue(AppConfig.shared().getInputSize());
		child = limitField.getView();

		c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 1;
		c.anchor = GridBagConstraints.LINE_END;
		rightView.add(child, c);

		//

		SSimpleGridView _view = new SSimpleGridView(1, 2);
		_view.setPreferredSize(new Dimension(0, 100));
		_view.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0,
				Color.lightGray));

		_view.add(queryArea.getView());
		_view.add(rightView);

		add(_view, BorderLayout.PAGE_END);
	}
}
